<?php

class Picture
{
	private $image;
	private $font;
	private $fontsize;
	private $colors;
	
	public function Picture($picture)
	{
		$picture_ext = end(explode('.', $picture));
		switch($picture_ext)
		{
			case 'jpg':
			case 'jpeg':
				$this->image = imagecreatefromjpeg($picture);
				break;
			case 'png':
				$this->image = imagecreatefrompng($picture);
				break;
			case 'gif':
				$this->image = imagecreatefromgif($picture);
				break;
		}
		
		$this->font = "fonts/visitor.ttf";
		$this->fontsize = 8;
		$this->colors = include 'colors.php';
	}
	
	public function AddColor($name, $r, $g, $b)
	{
		$this->colors[$name] = imagecolorallocate($this->image, $r, $g, $b);
	}
	
	public function DrawString($string, $x, $y, $color)
	{
		return imagettftext($this->image, $this->fontsize, 0, $x, $y + 5, $this->colors[$color], $this->font, $string);
	}
	
	public function DrawImage($image, $x, $y, $sx, $sy, $w, $h)
	{
		return imagecopy($this->image, $image, $x, $y, $sx, $sy, $w, $h);
	}	
	
	public function ShowImage($quality)
	{
		imagejpeg($this->image, null, $quality);
	}
	
	public function SaveImage($saveto, $quality)
	{
		imagejpeg($this->image, $saveto, $quality);
	}
	
	public function DestroyImage()
	{
		imagedestroy($this->image);
	}
}

?>